const { ipcMain, screen } = require('electron')
const { sendMainWin } = require('../window/mainWindow')
const { createControlWin } = require('../window/controlWindow')

const { getScreenId } = require('./peer-control.js')
const robotHandle = require('./robotHandle')

function createIpc() {
    // 主窗口：获取当前连接码
    ipcMain.handle('getConnectCode', (event, arg) => {
        const code = Math.floor(Math.random() * (999999 - 100000)) + 100000
        return code
    })
    // 主窗口：连接请求
    ipcMain.on('connectControl', (event, data) => {
        // console.log('收到请求连接')
        sendMainWin('changeStatus', data, '3') // 回复请求
        createControlWin() // 打开控制窗口
    })
    // 控制窗口：获取桌面id
    ipcMain.handle('update:sourceId', async () => {
        const screenId = await getScreenId() // 获取桌面流id
        return screenId 
    })
    // 操作傀儡端
    ipcMain.on('robot', (event, type, data) => {
        // robotHandle.emit(type, data)
    })
}

module.exports = createIpc